#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=5e3+10,MAXM=1e3+10;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int n,m,cnt,col[MAXM],head[MAXM];
struct edge1
{
	int u,v;
}e1[MAXM];
struct edge
{
	int v,next;
}e[MAXM*MAXM*2];
void addedge(int x,int y)
{
	e[++cnt]=(edge){y,head[x]};
	head[x]=cnt;
	return;
}
bool dfs(int u,int x)
{
	if(col[u])
	{
		if(col[u]==x)return true;
		return false;
	}
	col[u]=x;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(!dfs(v,x==1?2:1))return false;
	}
	return true;
}
int main()
{
	int T=read();
	while(T--)
	{
		memset(col,0,sizeof(col));
		memset(head,0,sizeof(head));
		cnt=0;
		n=read();m=read();
		for(int i=1;i<=m;++i)
		{
			int x=read(),y=read();
			e1[i].u=min(x,y);
			e1[i].v=max(x,y);
		}
		for(int i=1;i<=m;++i)
			for(int j=i+1;j<=m;++j)
				if(e1[i].u<e1[j].u&&e1[j].u<e1[i].v&&e1[i].v<e1[j].v||e1[j].u<e1[i].u&&e1[i].u<e1[j].v&&e1[j].v<e1[i].v)addedge(i,j),addedge(j,i);
		bool flag=true;
		for(int i=1;i<=m;++i)
			if(!col[i])
				if(!dfs(i,1))
				{
					flag=false;
					break;
				}
		flag?puts("sane"):puts("non");
	}
	return 0;
}
